<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="css/index.css"/>
    <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_ci1breot2kmlsor.css"/>
    <style>
        #demo7 {
            position: relative;
            bottom: 10px;
            right: 20px;
            float: right;
        }
    </style>
</head>
<body>
<section class="layui-larry-box">
    <!--设备监控-->
    <div class="larry-personal">

        <div class="layui-tab">
            <blockquote class="layui-elem-quote mylog-info-tit" style="background: #fff;">
                <ul class="handle-box" id="conditions">
                    <li class="handle-item"><span class="layui-form-label" style="line-height: 30px;">设备名称：</span>
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" placeholder="请输入设备名称" class="layui-input"
                                   v-model="deviceName">
                        </div>
                        <button class="layui-btn mgl-20" @click="getDeviceList">查询</button>
                    </li>
                    <li class="handle-item" style="padding-top: 10px;">
                        <span class="layui-form-label">设备类型：</span>
                        <div style="height: 38px; line-height: 38px;" class="btn_block">
                            <template v-for="(item, index) in deviceTypes">
                                <label v-if="index==0" class="layui-btn-block">{{item.typeName}}<input type="radio"
                                                                                                       name="sex1"
                                                                                                       :value="item.typeId"
                                                                                                       style="display: none;"
                                                                                                       v-model="deviceType"
                                                                                                       @change="getDeviceList"></label>
                                <label v-else class="layui-btn-none">{{item.typeName}}<input type="radio" name="sex1"
                                                                                             :value="item.typeId"
                                                                                             style="display: none;"
                                                                                             v-model="deviceType"
                                                                                             @change="getDeviceList"></label>
                            </template>
                        </div>
                    </li>
                    <li class="handle-item">
                        <span class="layui-form-label">应用场景：</span>
                        <div style="height: 38px; line-height: 38px;" class="btn_block">
                            <template v-for="(item, index) in monitorScene">
                                <label v-if="index==0" class="layui-btn-block">{{item.sceneName}}<input type="radio"
                                                                                                        name="scene_id"
                                                                                                        :value="item.sceneId"
                                                                                                        style="display: none;"
                                                                                                        v-model="sceneId"
                                                                                                        @change="getDeviceList"></label>
                                <label v-else class="layui-btn-none">{{item.sceneName}}<input type="radio"
                                                                                              name="scene_id"
                                                                                              :value="item.sceneId"
                                                                                              style="display: none;"
                                                                                              v-model="sceneId"
                                                                                              @change="getDeviceList"></label>
                            </template>
                        </div>

                    </li>
                    <li class="handle-item">
                        <span class="layui-form-label">设备状态：</span>
                        <div style="height: 38px; line-height: 38px;" class="btn_block device_state">
                            <label class="layui-btn-block">不限<input type="radio" name="sex3" value="-1"
                                                                    style="display: none;" v-model="deviceState"
                                                                    @change="getDeviceList"></label>
                            <label id="normal" class="layui-btn-none">正常<input type="radio" name="sex3" value="2"
                                                                               style="display: none;"
                                                                               v-model="deviceState"
                                                                               @change="getDeviceList"></label>
                            <label id="overrun" class="layui-btn-none">超限<input type="radio" name="sex3" value="1"
                                                                                style="display: none;"
                                                                                v-model="deviceState"
                                                                                @change="getDeviceList"></label>
                            <label id="abnormal" class="layui-btn-none">异常<input type="radio" name="sex3" value="0"
                                                                                 style="display: none;"
                                                                                 v-model="deviceState"
                                                                                 @change="getDeviceList"></label>
                            <label id="off-line" class="layui-btn-none">离线<input type="radio" name="sex3" value="3"
                                                                                 style="display: none;"
                                                                                 v-model="deviceState"
                                                                                 @change="getDeviceList"></label>
                        </div>
                    </li>
                </ul>
            </blockquote>

            <div class="layui-tab-item layui-field-box layui-show" v-run="loadTable()">
                <ul id="biuuu_city_list" style="width: 100%;">

                </ul>
            </div>


        </div>
    </div>
</section>
<div style="" id="demo7"></div>

<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/monitorings.js"></script>
<script type="text/javascript" src="js/vue/vue.js"></script>
<script src="//cdn.bootcss.com/jquery/3.2.0/jquery.js"></script>
<script src="//cdn.bootcss.com/vue-resource/1.2.1/vue-resource.js"></script>

<script>
    var deviceState = getQueryString("deviceState", window.location.href);
    //根据状态  设置颜色
    $(".device_state label").each(function () {
        if (deviceState != null && deviceState != "") {
            if ($(this).find('input').val() == deviceState) {
                $(this).addClass("layui-btn-block");
            } else {
                $(this).removeClass("layui-btn-block").addClass("layui-btn-none");
            }
        }

    });
    var vue = new Vue({
                el: '#conditions',
                data: {
                    deviceName: "",
                    deviceType: -1,
                    sceneId: -1,
                    deviceState: deviceState,
                    monitorScene: [],
                    deviceTypes: [],
                },
                mounted: function () {
                    this.$nextTick(function () {
                        var token = new Object();
                        token.accessToken = accessToken;
                        this.$http.get(url + "/ic-iot/users/" + adminId + "/devices/scenes",
                                {headers: token}).then(function (response) {
                            var res = response.body;
                            if (res.code == 1) {
                                var noScene = new Object();
                                noScene.sceneName = "不限";
                                noScene.sceneId = "-1";
                                this.monitorScene.push(noScene);
                                this.monitorScene = this.monitorScene.concat(res.result);
                            }
                        }).catch(function (response) {
                            console.log(response)
                        });
                        this.$http.get(url + "/ic-iot/users/" + adminId + "/devices/deviceTypes",
                                {headers: token}).then(function (response) {
                            var res = response.body;
                            if (res.code == 1) {
                                var noDeviceType = new Object();
                                noDeviceType.typeName = "不限";
                                noDeviceType.typeId = "-1";
                                this.deviceTypes.push(noDeviceType);
                                this.deviceTypes = this.deviceTypes.concat(res.result);
                            }
                        }).catch(function (response) {
                            console.log(response)
                        });
                        this.getDeviceList();
                    });
                },
                methods: {
                    getDeviceList: function () {
                        var params = new Object();
                        params.pageSize = 999;
                        params.currentPage = 1;
                        if (this.deviceName != "")
                            params.deviceName = this.deviceName;
                        if (this.deviceType != -1)
                            params.deviceType = this.deviceType;
                        if (this.deviceState != -1)
                            params.deviceState = this.deviceState;
                        if (this.sceneId != -1)
                            params.sceneId = this.sceneId;
                        var token = new Object();
                        token.accessToken = accessToken;
                        this.$http.get(url + "/ic-iot/admin/" + adminId + "/devicesWithRecords",
                                {params: params, headers: token}).then(function (response) {
                            var res = response.body;
                            if (res.code == 1) {
                                var result = res.result;
                                //$('#deviceTable').dataTable().fnClearTable();
                                drawCards(res);
                                if (result.length != 0)
                                    $('#deviceTable').dataTable().fnAddData(result);
                            }
                        }).catch(function (response) {
                            // console.log(response)
                        });
                    }
                }
            }
    );

</script>
</body>
</html>